{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = tf.placeholder(tf.float32, (100, 784))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "W = tf.Variable(tf.random_uniform((784, 100), -1, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "b = tf.Variable(tf.zeros((100)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](https://camo.githubusercontent.com/63e8470af161edd5d54326b509bf54465c369649/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f7376672e6c617465783f5c696e6c696e652673706163653b682673706163653b3d2673706163653b52654c552857782b6229)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](https://lh3.googleusercontent.com/C85HGtBGvwyZHZnIYnw0ij4xgY6BzDL_CqDQl64IxqgWOYi9qoSWthCswIXuCI-3p-Zn9gjv5T04hGiPYvC17FUpTrooyo8fsbetiG3GsM0x4Oy7AADLhHbeWz3j3XA_5gHimKpjnt58Dgfd_78hDQuJQKrOpDwMn-FyXPQt0zTHspWtGvujvt_-EtWJZAUaXRNAQbiT3T7_XpJnw02ZzX27D7_Legq2h8mPP0TCgSFjes2PexLgwxr8ixV76Pf0WbqUbC6eO86tEEvJnagHk_HQvr3ZLL5dMK5X24t6M2PWH8oJb35WhkE4o8S6vgQBkippJrlhsTBBNvJqs8wCy99Uu2-zZAWGvzO1wilVdEyUdg8LeZifzgYKnC_HjG_YZPJ0cUWH9RHRPaMBMxmhxup9eb5amU2BAfi85tx1OsShCR6aoeZrnNqCrDLz_FewlFt8wLsbQyJiX8L6GtW_g7--kcgWLGqfmRU4Pe8ekoYmggNFs0jTvtrZZXNTNsE4lkt1k616MIzKA_hqrVEDWMFkkrxVCBTKgOpc4LPgQsi4Fgpz0hXqh0iNTaE67FgabYX0YfKQMmw6ih4u3mkBsJeNmInQ-PALdjhDmAMqOGgWgoVFYCFeB0ggf23l7bJ3Gi8rFjRIW-d6j5ikDhm08etNG_EtXYNfG-CzzJkGfU4tDTCyQWjKMllD=w800-h400-no)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "h = tf.nn.relu(tf.matmul(x, W) + b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tensor(\"Relu:0\", shape=(100, 100), dtype=float32)\n"
     ]
    }
   ],
   "source": [
    "# Kiểm tra triều của h/\n",
    "print(h)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "sess = tf.Session()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "sess.run(tf.initialize_all_variables())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### **sess.run(fetches, feeds)**\n",
    "\n",
    "  **fetches**: Liệt kê tất cả **các đỉnh (nodes)** bạn muốn trả về giá trị, trong trường hợp này tôi muốn trả về giá trị của h\n",
    "  \n",
    "  **feeds**: một dictionary chứa tên biến đầu vào và giá trị của nó truyền vào trong Graph, ở đây tôi có biến **x** và giá trị ngẫu nhiên khởi tạo bằng hàm np.random.random."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.       ,  9.201424 ,  0.       , ...,  0.       ,  0.       ,\n",
       "         0.       ],\n",
       "       [ 0.       , 13.298065 ,  0.       , ...,  0.       ,  1.2823265,\n",
       "         0.       ],\n",
       "       [ 0.       ,  4.288911 ,  0.       , ...,  6.110207 ,  3.9334798,\n",
       "         0.       ],\n",
       "       ...,\n",
       "       [ 0.       ,  4.820806 ,  0.       , ...,  4.610816 ,  4.833015 ,\n",
       "         6.31176  ],\n",
       "       [ 0.       ,  0.       ,  0.       , ...,  9.902921 ,  1.8157439,\n",
       "         0.       ],\n",
       "       [ 0.       ,  7.734725 ,  0.       , ...,  4.4870186,  0.       ,\n",
       "         1.8016957]], dtype=float32)"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sess.run(h, {x: np.random.random((100, 784))})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
